package com.burstly.lib.util.json;

import com.burstly.jackson.JsonGenerationException;
import com.burstly.jackson.JsonGenerator;
import com.burstly.jackson.JsonParseException;
import com.burstly.jackson.JsonProcessingException;
import com.burstly.jackson.Version;
import com.burstly.jackson.annotate.JsonAutoDetect.Visibility;
import com.burstly.jackson.annotate.JsonMethod;
import com.burstly.jackson.map.DeserializationConfig.Feature;
import com.burstly.jackson.map.JsonMappingException;
import com.burstly.jackson.map.JsonSerializer;
import com.burstly.jackson.map.ObjectMapper;
import com.burstly.jackson.map.SerializerProvider;
import com.burstly.jackson.map.annotate.JsonSerialize.Inclusion;
import com.burstly.jackson.map.module.SimpleModule;
import com.burstly.jackson.map.type.TypeFactory;
import com.burstly.jackson.type.TypeReference;
import com.burstly.lib.network.ResponseObject;
import com.burstly.lib.network.beans.cookie.CookieHolder;
import com.burstly.lib.util.LoggerExt;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

class JacksonProcessor
  implements IJsonProcessor
{
  private static final ObjectMapper JACKSON_MAPPER;
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "Jackson Processor";

  static
  {
    JACKSON_MAPPER = new ObjectMapper();
    configureMapper(JACKSON_MAPPER);
    SimpleModule localSimpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, null));
    localSimpleModule.addSerializer(new CookieSerializer(null));
    JACKSON_MAPPER.registerModule(localSimpleModule);
  }

  private static void configureMapper(ObjectMapper paramObjectMapper)
  {
    paramObjectMapper.setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
    paramObjectMapper.setVisibility(JsonMethod.CREATOR, JsonAutoDetect.Visibility.ANY);
    paramObjectMapper.setVisibility(JsonMethod.GETTER, JsonAutoDetect.Visibility.NONE);
    paramObjectMapper.setVisibility(JsonMethod.SETTER, JsonAutoDetect.Visibility.NONE);
    paramObjectMapper.setVisibility(JsonMethod.IS_GETTER, JsonAutoDetect.Visibility.NONE);
    paramObjectMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    paramObjectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  }

  public ResponseObject fromJson(String paramString)
  {
    try
    {
      ResponseObject localResponseObject = new ResponseObject((HashMap)JACKSON_MAPPER.readValue(paramString, TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class)));
      return localResponseObject;
    }
    catch (JsonParseException localJsonParseException)
    {
      LOG.logError("Jackson Processor", "Error parsing server response! Response: {0} is not valid JSON string.", new Object[] { paramString });
      LOG.logThrowable("Jackson Processor", localJsonParseException);
      return null;
    }
    catch (JsonMappingException localJsonMappingException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "Error mapping server response! Response: {0} is not valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localJsonMappingException);
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "IO error during parsing server response! Response: {0} is not valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localIOException);
      }
    }
  }

  public <T> T fromJson(String paramString, Class<T> paramClass)
  {
    try
    {
      Object localObject = JACKSON_MAPPER.readValue(paramString, paramClass);
      return localObject;
    }
    catch (JsonParseException localJsonParseException)
    {
      LOG.logError("Jackson Processor", "Error parsing a json string! The string: {0} is not a valid JSON string.", new Object[] { paramString });
      LOG.logThrowable("Jackson Processor", localJsonParseException);
      return null;
    }
    catch (JsonMappingException localJsonMappingException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "Error mapping a json string! The string: {0} is not a valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localJsonMappingException);
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "IO error during parsing a json string! The string: {0} is not a valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localIOException);
      }
    }
  }

  public List<String> fromJsonToListOfStrings(String paramString)
  {
    try
    {
      List localList = (List)JACKSON_MAPPER.readValue(paramString, new TypeReference()
      {
      });
      return localList;
    }
    catch (JsonParseException localJsonParseException)
    {
      LOG.logError("Jackson Processor", "Error parsing json list of strings! Response: {0} is not valid JSON string.", new Object[] { paramString });
      LOG.logThrowable("Jackson Processor", localJsonParseException);
      return null;
    }
    catch (JsonMappingException localJsonMappingException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "Error mapping json list of strings! Response: {0} is not valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localJsonMappingException);
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        LOG.logError("Jackson Processor", "IO error during parsing json list of strings! Response: {0} is not valid JSON string.", new Object[] { paramString });
        LOG.logThrowable("Jackson Processor", localIOException);
      }
    }
  }

  public String toJson(Object paramObject)
  {
    try
    {
      String str = JACKSON_MAPPER.writeValueAsString(paramObject);
      return str;
    }
    catch (JsonGenerationException localJsonGenerationException)
    {
      LoggerExt localLoggerExt3 = LOG;
      Object[] arrayOfObject3 = new Object[1];
      arrayOfObject3[0] = paramObject.toString();
      localLoggerExt3.logError("Jackson Processor", "Error generating JSON string! Object: {0}", arrayOfObject3);
      LOG.logThrowable("Jackson Processor", localJsonGenerationException);
      return null;
    }
    catch (JsonMappingException localJsonMappingException)
    {
      while (true)
      {
        LoggerExt localLoggerExt2 = LOG;
        Object[] arrayOfObject2 = new Object[1];
        arrayOfObject2[0] = paramObject.toString();
        localLoggerExt2.logError("Jackson Processor", "Error mapping JSON string! Object: {0}", arrayOfObject2);
        LOG.logThrowable("Jackson Processor", localJsonMappingException);
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        LoggerExt localLoggerExt1 = LOG;
        Object[] arrayOfObject1 = new Object[1];
        arrayOfObject1[0] = paramObject.toString();
        localLoggerExt1.logError("Jackson Processor", "IO error during generating JSON string! Object: {0}", arrayOfObject1);
        LOG.logThrowable("Jackson Processor", localIOException);
      }
    }
  }

  private static class CookieSerializer extends JsonSerializer<CookieHolder>
  {
    private static final String NAME = "name";
    private static final String VALUE = "value";

    public Class<CookieHolder> handledType()
    {
      return CookieHolder.class;
    }

    public void serialize(CookieHolder paramCookieHolder, JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider)
      throws IOException, JsonProcessingException
    {
      paramJsonGenerator.writeStartObject();
      paramJsonGenerator.writeStringField("name", paramCookieHolder.getName());
      paramJsonGenerator.writeStringField("value", paramCookieHolder.getValue());
      paramJsonGenerator.writeEndObject();
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.util.json.JacksonProcessor
 * JD-Core Version:    0.6.2
 */